package edu.cmu.cs211.exprtree.tests;

import static org.junit.Assert.assertEquals;
import java.math.BigDecimal;
import org.junit.Test;
import edu.cmu.cs211.exprtree.ast.ConstantExpression;


public abstract class ConstantExpressionTest extends ExpressionTestUtil {

	public abstract ConstantExpression createExpr(BigDecimal x);

	@Test
	public void testConstructor() {
		ConstantExpression x = createExpr(BigDecimal.ONE);
		assertEquals("ONE", BigDecimal.ONE, x.getValue());
		ConstantExpression y = createExpr(BigDecimal.ZERO);
		assertEquals("ZERO", BigDecimal.ZERO, y.getValue());
	}

	@Test(expected = NullPointerException.class)
	public void testValueNull() {
		createExpr(null);
	}


	public void toStringTest(String operand) {
		ConstantExpression x1 = createExpr(BigDecimal.ONE);
		ConstantExpression x2 = createExpr(BigDecimal.ZERO);
		
		String one = ConstantExpression.ONE.toString();
		String zero = ConstantExpression.ZERO.toString();

		assertEquals("toString incorrect", String.format("(%s)", one), x1
				.toString());
		assertEquals("toString incorrect", String.format("(%s)", zero), x2
				.toString());
	}

}
